package com.niit.common

import com.niit.utils.SparkUtils
import org.apache.spark.SparkConf
import org.apache.spark.streaming.Seconds

trait TApp {

  def start(master:String = "local[*]",appName:String = "application")(op : => Unit):Unit={
    val sparkConf = new SparkConf().setMaster(master).setAppName(appName)

    val sc = SparkUtils.createSpark(sparkConf,Seconds(5))
    val spark = SparkUtils.takeSpark()
    val ssc = SparkUtils.takeSSC()

    sc.setLogLevel("ERROR")

    try{
      op  // 表示要执行的代码
    }catch {
      case  ex => ex.printStackTrace()
    }

    spark.close()
    ssc.stop(true,true)
    sc.stop()
    SparkUtils.clear()


  }

}
